<?php //status.php
include_once 'header.php';

if (isset($_POST['company_name'])) $company_name=$_POST['company_name'];
else $company_name="ericsson";

echo $company_name;

$sql="SELECT company_name FROM company"; 
$result=mysql_query($sql); 
$options=""; 

while ($row=mysql_fetch_array($result)) {

    $company_name=$row["company_name"];
    $options.="<OPTION VALUE=\"$company_name\">".$company_name.'</option>';
}

echo<<<_END
<html>
	<head>
		<title>Form test</title>
	</head>
	<body>
	<form method="post" action="status.php" />
		
		<SELECT NAME=company_name><OPTION VALUE=0><?=$options?></SELECT>
		<input type="submit" value="search" />
	</form>
	this is : $company_name<br/>
	</body>
</html>
_END;


$company_name=$_POST['company_name'];
echo $company_name;
$result = mysql_query("SELECT company_id FROM company WHERE company_name='$company_name'");   
$company_no= mysql_result($result,0);

$result = mysql_query("SELECT B.company_name,B.type, D.model_name, D.model_type FROM company AS B LEFT OUTER JOIN 
(SELECT * FROM model AS A, company_to_model AS C WHERE A.model_name = C.model_nam) as D on B.company_id = D.company_id WHERE B.company_id = $company_no");
if (!$result) {
    die("Query to show fields from table failed");
}

$fields_num = mysql_num_fields($result);

echo "<h1>Table: {$name}</h1>";
echo "<table border='1'><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++)
{
    $field = mysql_fetch_field($result);
    echo "<td>{$field->name}</td>";
}
echo "</tr>\n";
// printing table rows
while($row = mysql_fetch_row($result))
{
    echo "<tr>";
    // $row is array... foreach( .. ) puts every element
    // of $row to $cell variable
    foreach($row as $cell)
        echo "<td>$cell</td>";

    echo "</tr>\n";
}

$result = mysql_query("SELECT * FROM patent WHERE company_id = $company_no");
if (!$result) {
    die("Query to show fields from table failed");
}

$fields_num = mysql_num_fields($result);

echo "<table border='1'><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++)
{
    $field = mysql_fetch_field($result);
    echo "<td>{$field->name}</td>";
}
echo "</tr>\n";
// printing table rows
while($row = mysql_fetch_row($result))
{
    echo "<tr>";
    // $row is array... foreach( .. ) puts every element
    // of $row to $cell variable
    foreach($row as $cell)
        echo "<td>$cell</td>";

    echo "</tr>\n";
}
mysql_free_result($result);
?>